//************************************************
//  *Author：jxx
//  *QQ：283591387
//  *自定义业务逻辑扩展
//************************************************
import { mapMutations } from 'vuex';
import extend from './q_install_request_notarizeExtend.js';
import options from './q_install_request_notarizeOptions.js';
export default function () {
	return {
		data() {
			let _options = options();
			_options.extend = extend;
			return {
				options: _options
			};
		},
		methods: {
			...mapMutations(['setSalesContractDataStore']),
			onInited() {
				//页面参数初始化
				this.editFormOptions.forEach((item) => {
					if (item.field == 'Voucher_sub_install_request') {
						item.testVal = '点击选择安装申请单';
						item.required = true;
						item.focusUrl = '/pages/aftersaleinfo/q_install_request/q_install_request';
					}
				});
				//设置自定义格式显示
				this.columns.forEach((column) => {
					if (column.field == 'Gong_shi') {
						//column.field == 'Attachment'||
						//自定义格式化显示,在下面的formatter实现具体逻辑
						column.formatter = true;

						//开启table单元格点击事件(仅设置this.direction = 'horizontal属性后生效)
						// column.click=true;

						//指定字段为date类型不显示时分秒
						//column.type="date";
						//设置列宽度
						//column.width = 70;
					}
				});

				//页面打开时禁用加载数据
				//this.load=false;
				//页面打开时默认弹出查询框
				//this.searchModel = true;
			},
			formatter(row, column, index) {
				//自定义格式化
				// console.log('formatter-row', row);
				if (column.field == 'Gong_shi') {
					return row[column.field] ? row[column.field] + ' 天' : '';
				}
				// if (column.field == 'Attachment' && row[column.field]) {
				// 	// console.log("row[column.field]",row[column.field]);
				// 	const arr = row[column.field].split(',');
				// 	// console.log("arr",arr);
				// 	const regex = new RegExp(/\//g, 'g');
				// 	let index = null;
				// 	let nameArr = [];
				// 	arr.forEach((item) => {
				// 		const itemName = item.split('/');
				// 		const name = itemName[itemName.length - 1];
				// 		nameArr.push(name);
				// 	});
				// 	return `<span style="color: #0189ff;padding: 2px 10px;
				// 							         font-size: 10px;"> ${nameArr.join(',')}</span>`;
				// }
				return '';
			},
			rowClick(index, row, column) {
				//行点击事件(默认触发编辑)
				// let url = '/pages/aftersaleinfo/q_serve_contract/Detail/Detail?salesinfo=' + row.Serve_contract;
				// uni.navigateTo({
				// 	url: url
				// });
				return false;
				// return true;
			},
			cellClick(index, row, column) {
				//单元格击事件(默认触发编辑)
				//仅onInited中设置：this.direction = "horizontal", this.columns的字段设置为click=true后生效
				return true;
			},
			rowButtons(index, row) {
				//列表显示的按钮
				//自定义按钮,仅onInited中设置：this.direction = "list"后生效
				let buttonList = [];
				if (row.AuditStatus === 0) {
					buttonList.push({
						text: '审核',
						type: 'error',
						shape: 'circle'
					});
					if (buttonList.length != 2) {
						buttonList.push({
							text: '编辑',
							type: 'warning',
							shape: 'circle'
						});
					}
				} else {
					buttonList.push({
						text: '查看审核',
						type: 'primary',
						shape: 'circle'
					});
				}
				//返回查看审批按钮
				return buttonList;
			},
			rowButtonClick(btn, index, row) {
				//列表显示的按钮点击事件
				if (btn.text == '编辑') {
					//这里key 要和 url上的biaoming一致
					uni.setStorageSync('q_install_request_notarize', row);
					const optionsObj = {
						editFormOptions: this.options.editFormOptions,
						detailtable: this.options.table
					};
					uni.setStorageSync('optionsObj', JSON.stringify(optionsObj));
					uni.navigateTo({
						url: '/pages/addPage/addPage?biaoming=q_install_request_notarize&currentAction=Update&ID=Install_request_notarize&detailTableShow=false'
					});
					return;
				}
				try {
					this.setSalesContractDataStore({ workTable: 'q_install_request_notarize', tableKey: row.Install_request_notarize });
					uni.navigateTo({
						url:
							`/pages/aftersaleinfo/q_install_request_notarize/q_install_request_notarizeAduit?workTable=q_install_request_notarize&&tableKey=` +
							row.Install_request_notarize
						// url: `pages/flow/audit/audit?workTable=q_sales_contract&tableKey=${row.Sales_contract}`
					});
				} catch (e) {
					//TODO handle the exception
					console.log(e);
				}
			},
			searchBefore(params) {
				//查询前
				return true;
			},
			updateBefore(formData) {
				//更新保存前操作
				return true;
			},
			addBefore(formData) {
				//新建保存前操作
				return true;
			},
			searchFormOnChange(field, value) {
				//查询弹出框下拉框或日期选中事件
				//if(field=="字段"){
				// 	console.log(value)
				//}
			},
			editFormOnChange(field, value) {
				//新建编辑弹出框下拉框或日期选中事件
				//if(field=="字段"){
				// 	console.log(value)
				//}
			}
		}
	};
}
